{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-31T10:28:00.561944Z",
     "start_time": "2025-03-31T10:28:00.548931Z"
    }
   },
   "source": "from urllib.request import urlopen",
   "outputs": [],
   "execution_count": 40
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-31T10:28:01.024726Z",
     "start_time": "2025-03-31T10:28:01.018734Z"
    }
   },
   "cell_type": "code",
   "source": "url = \"https://www.baidu.com/\"",
   "id": "a2dff722888fd131",
   "outputs": [],
   "execution_count": 41
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-31T10:28:01.940110Z",
     "start_time": "2025-03-31T10:28:01.745801Z"
    }
   },
   "cell_type": "code",
   "source": "resp = urlopen(url)",
   "id": "f8109aac0cd0d330",
   "outputs": [],
   "execution_count": 42
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-31T10:28:02.589916Z",
     "start_time": "2025-03-31T10:28:02.576904Z"
    }
   },
   "cell_type": "code",
   "source": [
    "with open(\"mybaidu.html\", mode=\"w\", encoding=\"utf-8\") as f:  \n",
    "        f.write(resp.read().decode(\"UTF-8\"))"
   ],
   "id": "c4998338057b9414",
   "outputs": [],
   "execution_count": 43
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "读取到的是源代码，是html文件",
   "id": "1238b678eba60c47"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-03T08:05:17.027406Z",
     "start_time": "2025-04-03T08:05:17.006709Z"
    }
   },
   "cell_type": "code",
   "source": "print(\"over!\")",
   "id": "7ec17b18cdb723a2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "over!\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-31T10:27:56.705231Z",
     "start_time": "2025-03-31T10:27:56.695404Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "f3975ceeebc13704",
   "outputs": [],
   "execution_count": 39
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-31T10:27:54.423259Z",
     "start_time": "2025-03-31T10:27:54.410156Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "485b64df5536f424",
   "outputs": [],
   "execution_count": 34
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "19e36518a592d904"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
